home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Mark Pilgrim / Dialectic 1.2 / source / Dialectic ƒ / Dialectic code / dialectic utilities.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-30  |  2.8 KB  |  124 lines  |  [TEXT/KAHL]

  1. /**********************************************************************\
  2.  
  3. File:        dialectic utilities.c
  4.  
  5. Purpose:    This module contains various utilities which the raw
  6.             dialect routines use in converting text.
  7.             
  8.  
  9.  
  10. Dialectic -=- dialect text conversion extraordinare
  11. Copyright ©1994, Mark Pilgrim
  12.  
  13. This program is free software; you can redistribute it and/or modify
  14. it under the terms of the GNU General Public License as published by
  15. the Free Software Foundation; either version 2 of the License, or
  16. (at your option) any later version.
  17.  
  18. This program is distributed in the hope that it will be useful,
  19. but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  21. GNU General Public License for more details.
  22.  
  23. You should have received a copy of the GNU General Public License
  24. along with this program in a file named "GNU General Public License".
  25. If not, write to the Free Software Foundation, 675 Mass Ave,
  26. Cambridge, MA 02139, USA.
  27.  
  28. \**********************************************************************/
  29.  
  30. #include "dialectic utilities.h"
  31. #include "program globals.h"
  32.  
  33. Boolean IsAllCaps(Str255 theWord)
  34. {
  35.     int                i;
  36.     
  37.     for (i=1; i<=theWord[0]; i++)
  38.         if (!IsUpperAlpha(theWord[i]))
  39.             return FALSE;
  40.     
  41.     return TRUE;
  42. }
  43.  
  44. unsigned char GetRestOfWord(Str255 theWord)
  45. {
  46.     int                i;
  47.     
  48.     i=0;
  49.     theWord[0]=0x00;
  50.     while ((theWord[0]<0xFF) && (IsAlpha(NextChar(i))))
  51.         theWord[++theWord[0]]=NextChar(i++);
  52.     
  53.     return theWord[0];
  54. }
  55.  
  56. Boolean IsAlpha(char thisChar)
  57. {
  58.     return ((((thisChar|0x20)>='a') && ((thisChar|0x20)<='z')) || (thisChar==0x27) ||
  59.             (thisChar=='’'));
  60. }
  61.  
  62. Boolean IsUpperAlpha(char thisChar)
  63. {
  64.     return (((thisChar>='A') && (thisChar<='Z')) || (thisChar==0x27) || (thisChar=='’'));
  65. }
  66.  
  67. Boolean IsNumeric(char thisChar)
  68. {
  69.     return ((thisChar>='0') && (thisChar<='9'));
  70. }
  71.  
  72. Boolean IsVowel(char thisChar)
  73. {
  74.     char        lowerChar;
  75.     
  76.     lowerChar=thisChar|0x20;
  77.     return ((lowerChar=='a') || (lowerChar=='e') || (lowerChar=='i') ||
  78.             (lowerChar=='o') || (lowerChar=='u'));
  79. }
  80.  
  81. Boolean IsConsonant(char thisChar)
  82. {
  83.     return (IsAlpha(thisChar) && (!IsVowel(thisChar)));
  84. }
  85.  
  86. char ThisChar(void)
  87. {
  88.     if (gInputOffset>=INPUT_BUFFER_MAX)
  89.         gInputNeedsUpdate=TRUE;
  90.     if (gAbsoluteOffset>=gInputLength)
  91.         return 0x00;
  92.     else
  93.         return *((char*)((long)gInputBuffer+gInputOffset));
  94. }
  95.  
  96. char NextChar(int howmany)
  97. {
  98.     if (gAbsoluteOffset+howmany>=gInputLength)
  99.         return 0x00;
  100.     else
  101.         return *((char*)((long)gInputBuffer+gInputOffset+howmany));
  102. }
  103.  
  104. void StoreChar(char thisChar)
  105. {
  106.     *((char*)((long)gOutputBuffer+(gOutputOffset++)))=thisChar;
  107.     if (gOutputOffset>=OUTPUT_BUFFER_MAX)
  108.         gOutputNeedsUpdate=TRUE;
  109. }
  110.  
  111. void StoreString(Str255 thisString)
  112. {
  113.     int                i;
  114.     
  115.     for (i=1; i<=thisString[0]; i++)
  116.         StoreChar(thisString[i]);
  117. }
  118.  
  119. void InputPlus(int howmany)
  120. {
  121.     gInputOffset+=howmany;
  122.     gAbsoluteOffset+=howmany;
  123. }
  124.